package com.missilike.core.config;

import cn.jiguang.common.ClientConfig;
import cn.jpush.api.JPushClient;
import com.missilike.core.domain.JPushProperties;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class JPushConfig {

    @Bean
    @ConfigurationProperties(prefix = "jpush")
    public JPushProperties jpushProperties() {
        return new JPushProperties();
    }

    @Bean
    public JPushClient jpushClient(JPushProperties jpushProperties) {
        if (StringUtils.isEmpty(jpushProperties.getAppKey()) || StringUtils.isEmpty(jpushProperties.getMasterSecret())) {
            log.warn("JPushProperties has not appKey and masterSecret");
            return null;
        }
        return new JPushClient(jpushProperties.getMasterSecret(), jpushProperties.getAppKey(), null, ClientConfig.getInstance());
    }
}
